package com.cskaoyan.service;

import com.cskaoyan.bean.Region;
import com.cskaoyan.bean.RegionCity;
import com.cskaoyan.bean.RegionCounty;
import com.cskaoyan.bean.RegionProvince;
import com.cskaoyan.mapper.RegionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author pengyehua
 * @date 2020/12/5 20:53
 */
@Service
public class AdminRegionServiceImpl implements AdminRegionService{

    @Autowired
    RegionMapper regionMapper;

    /**
     * 查询所有的行政区域
     * @return
     */
    @Override
    public List<RegionProvince> queryRegionList() {
        List<RegionProvince> provinceList = regionMapper.selectProvinceByPid(0);
        for (RegionProvince regionProvince : provinceList) {
            List<RegionCity> cityList = regionMapper.selectCityByPid(regionProvince.getId());
            for (RegionCity regionCity : cityList) {
                List<Region> RegionList = regionMapper.selectRegionByPid(regionCity.getId());
                regionCity.setChildren(RegionList);
            }
            regionProvince.setChildren(cityList);
        }
        return provinceList;
    }
}
